package com.letv.android.client.episode.parser;

import org.json.JSONObject;

import com.alibaba.fastjson.JSON;
import com.letv.core.bean.TabTopicAllDataBean;
import com.letv.core.bean.TabTopicAllDataBean.TabTopicDesc;
import com.letv.core.bean.TabTopicAllDataBean.TabTopicZtList;
import com.letv.core.parser.LetvMobileParser;

public class TabTopicCombineEpisodeParser extends LetvMobileParser<TabTopicAllDataBean> {
    private static final String TABDESC = "tabDesc";
    private static final String TABZTLIST = "tabZtList";
    
    private static final String SUBJECT = "subject";
    private static final String TABALBUMLIST = "tabAlbumList";
    private static final String TABVIDEOLIST = "tabVideoList";
    private static final String VIDEOINFO = "videoInfo";
    
    TabTopicAllDataBean mTabTopicAllDataBean;
    
    @Override
    protected TabTopicAllDataBean parse(JSONObject data) {
        if (data == null) {
            return null;
        }        
        
        mTabTopicAllDataBean = new TabTopicAllDataBean();
        if (has(data, TABDESC)) {
            mTabTopicAllDataBean.setTabTopicDesc(JSON.parseObject(getString(data, TABDESC), TabTopicDesc.class));
        }
        if (has(data, TABZTLIST)){
            mTabTopicAllDataBean.setTabTopicZtList(JSON.parseObject(getString(data, TABZTLIST), TabTopicZtList.class));
        }
        
        int count = 0;
        JSONObject ztObject = getJSONObject(data, TABZTLIST);
        if (has(ztObject, SUBJECT)) {
            count++;
        }
        if (has(ztObject, TABALBUMLIST)) {
            count++;
        }
        if (has(ztObject, TABVIDEOLIST)) {
            count++;
        }
        if (count == 3) {
            mTabTopicAllDataBean.setNormalVideo(true);
        }
        else {
            mTabTopicAllDataBean.setNormalVideo(false);
        }
        mTabTopicAllDataBean.setColumnNum(count);
        return mTabTopicAllDataBean;
        
    }
}
